package com.sjgs.gis;

import org.springframework.beans.BeansException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Properties;
@SpringBootApplication(
        exclude = {MongoAutoConfiguration.class,
                MongoDataAutoConfiguration.class,
                MongoRepositoriesAutoConfiguration.class}
)
@EnableDiscoveryClient
public class GeoserverDnApplication implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(GeoserverDnApplication.class);
        ConfigurableApplicationContext context = app.run(args);
        ConfigurableEnvironment env = context.getEnvironment();
        GeoserverDnApplication App = applicationContext.getBean(GeoserverDnApplication.class);
        context.setEnvironment(App.setEnv(env));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public ConfigurableEnvironment setEnv(ConfigurableEnvironment env) {
        return env;
    }

    @Component
    @Order(1)
    class Runner1 implements CommandLineRunner {
        @Override
        public void run(String... args) throws Exception {
            System.out.println("Step 3: The Runner1 run ...");
        }
    }
}
